package com.example.demo1.iot;

import com.example.demo1.core.annotation.DataSource;
import com.example.demo1.core.constants.DataSourcesName;
import com.example.demo1.core.entity.iot.Weather;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WeatherService {

	@Autowired
	private WeatherMapper weatherMapper;
	
	@DataSource(name = DataSourcesName.TAOS)
	public boolean init() {

		weatherMapper.createDB();
		weatherMapper.createTable();

		return true;
	}

	@DataSource(name = DataSourcesName.TAOS)
	public List<Weather> query(Long limit, Long offset) {
		return weatherMapper.select(limit, offset);
	}

	@DataSource(name = DataSourcesName.TAOS)
	public int save(int temperature, float humidity) {
		Weather weather = new Weather();
		weather.setTemperature(temperature);
		weather.setHumidity(humidity);

		return weatherMapper.insert(weather);
	}

	@DataSource(name = DataSourcesName.TAOS)
	public int save(List<Weather> weatherList) {
		return weatherMapper.batchInsert(weatherList);
	}

}